package com.jay.test.designModel.creater.staticFactory;

/**
 * 静态工厂(注: 只返回产品的抽象[即接口])
 * 包含两种实现策略
 * 1. 根据传入的operator名进行实例化对象
 * 2. 直接调用相应的构造实例的方法
 * Created by jifang on 15/12/7.
 */
public class OperatorFactory {

    public static Operator<Integer> createOperator(String operName) {
        Operator<Integer> operator;
        switch (operName) {
            case "+":
                operator = new AddOperator();
                break;
            case "*":
                operator = new MultiOperator();
                break;
            default:
                throw new RuntimeException("Wrong Operator Name: " + operName);
        }
        return operator;
    }

    /* ** 第二种实现策略 ** */
    public static Operator<Integer> createAddOper() {
        return new AddOperator();
    }

    public static Operator<Integer> createMultiOper() {
        return new MultiOperator();
    }
}